﻿<sdk:Page x:Class="SampleBrowser.Views.SampleFormFilling" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           xmlns:doc="http://schemas.firstfloorsoftware.com/documenttoolkit"
           xmlns:behaviors="clr-namespace:SampleBrowser.Behaviors"
           xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Form Filling">
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" Text="Form Filling"/>

        <doc:DocumentDataSource x:Name="DataSource" LoadError="DataSource_LoadError" />

        <doc:DocumentViewer x:Name="Viewer"
                            Grid.Row="1"
                            DocumentDataSource="{Binding ElementName=DataSource}">
            
            <!-- set the view mode scale to 100%-->
            <doc:DocumentViewer.ViewMode>
                <doc:ViewMode Scale="1" />
            </doc:DocumentViewer.ViewMode>
            
            <!-- define a custom template with the FormFillBehavior-->
            <doc:DocumentViewer.Template>
                <ControlTemplate TargetType="doc:DocumentViewer">
                    <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <ScrollViewer x:Name="ScrollViewer" Background="Transparent" BorderThickness="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                            <ItemsControl x:Name="Pages">
                                <i:Interaction.Behaviors>
                                    <doc:PageVirtualizer />
                                </i:Interaction.Behaviors>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Grid Width="{Binding DesiredPageContainerSize.Width}"
                                          Height="{Binding DesiredPageContainerSize.Height}">
                                            <Border Background="White" BorderBrush="{StaticResource SliderTrackBrush}" BorderThickness="1" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Center">
                                                <doc:FixedPageViewer FixedPage="{Binding FixedPage}" 
                                                                     FixedPageSize="{Binding FixedPageSize}"
                                                                     FixedPageError="{Binding FixedPageError}"
                                                                     Scale="{Binding DesiredPageScale}">
                                                    <i:Interaction.Behaviors>
                                                        <!-- enable link navigation -->
                                                        <doc:NavigationBehavior TextContainer="{Binding TextContainer}" />
                                                        <!-- enable form filling -->
                                                        <behaviors:FormFillBehavior />
                                                        
                                                    </i:Interaction.Behaviors>
                                                </doc:FixedPageViewer>
                                            </Border>
                                        </Grid>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </doc:DocumentViewer.Template>
        </doc:DocumentViewer>

        <doc:PageNavigator x:Name="Navigator"
                           Grid.Row="2"
                           Margin="0,8,0,0"
                           HorizontalAlignment="Center"
                           PageCount="{Binding PageCount, ElementName=Viewer}"
                           PageIndex="{Binding PageIndex, ElementName=Viewer, Mode=TwoWay}" />
    </Grid>
</sdk:Page>
